package com.kd.user.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.kd.user.entity.User;
import com.kd.user.entity.UserCondition;
import com.kd.user.mapper.UserMapper;
import com.kd.user.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;
    @Override
    public User queryByKey(String id) {

        return userMapper.selectByPrimaryKey(id);
    }

    @Override
    public PageInfo<User> queryAllUser(int pageNum,int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<User> list = userMapper.selectAllUser();
        return new PageInfo<>(list);
    }
    @Override
    public PageInfo<User> queryUserByCondition(UserCondition condition,int pageNum,int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<User> list =userMapper.selectByCondition(condition);
        return new PageInfo<>(list);
    }
    @Override
    public boolean removeUser(String id) {

        return userMapper.deleteByPrimaryKey(id)>0;
    }
    @Override
    public boolean updateById(User user){

        return userMapper.updateById(user)>0;
    }
    @Override
    public boolean addUser(User user){

        return userMapper.insertUser(user)>0;
    }
}
